import type { Meta, StoryObj } from "@storybook/react";
import { fn } from "@storybook/test";
import "../../styles/index.scss";
import { library } from "@fortawesome/fontawesome-svg-core";
import { fas } from "@fortawesome/free-solid-svg-icons";
import Menu, { MenuMode } from "./menu";
import MenuItem from "./menuItem";
import SubMenu from "./subMenu";
library.add(fas);
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
const meta = {
  title: "components/Menu",
  component: Menu,
  parameters: {
    // Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
    layout: "centered",
  },
  // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
  tags: ["autodocs"],
  // More on argTypes: https://storybook.js.org/docs/api/argtypes
  argTypes: {
    mode: {
      control: "radio",
      options: Object.values(MenuMode),
      description: "类型",
    },
    defaultIndex: { control: "number", description: "默认选中" },
    defaultOpenSubMenus: { control: "text", description: "默认展开子菜单" },
  },
  // Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args
  args: { onSelect: fn() },
} satisfies Meta<typeof Menu>;

export default meta;
type Story = StoryObj<typeof meta>;

export const differentMode: Story = {
  render: () => (
    <>
      <Menu mode={MenuMode.Horizontal}>
        <MenuItem>111</MenuItem>
        <MenuItem disabled>222</MenuItem>
        <MenuItem>333</MenuItem>
      </Menu>
      <div style={{ height: "20px" }}></div>
      <Menu mode={MenuMode.Vertical}>
        <MenuItem>111</MenuItem>
        <MenuItem disabled>222</MenuItem>
        <MenuItem>333</MenuItem>
      </Menu>
    </>
  ),
};

export const DifferentSubMenu: Story = {
  render: () => (
    <>
      <Menu mode={MenuMode.Horizontal} defaultOpenSubMenus={["2-0"]}>
        <MenuItem>111</MenuItem>
        <MenuItem>222</MenuItem>
        <MenuItem disabled>222</MenuItem>
        <SubMenu title="dropdown">
          <MenuItem disabled>222</MenuItem>
          <MenuItem disabled>222</MenuItem>
          <MenuItem>111</MenuItem>
        </SubMenu>
      </Menu>
      <div style={{ height: "20px" }}></div>
      <Menu mode={MenuMode.Vertical} defaultOpenSubMenus={["2-0"]}>
        <MenuItem>111</MenuItem>
        <MenuItem>222</MenuItem>
        <MenuItem disabled>222</MenuItem>
        <SubMenu title="dropdown">
          <MenuItem disabled>222</MenuItem>
          <MenuItem disabled>222</MenuItem>
          <MenuItem>111</MenuItem>
        </SubMenu>
      </Menu>
    </>
  ),
};
